package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;

public class JdbcTest2 {
    public static void main(String[] args) throws Exception{

        Scanner sc = new Scanner(System.in);

        String name = sc.next();
        int age = sc.nextInt();
        String sex = sc.next();

        //1、通过反射加载驱动
        Class.forName("com.mysql.jdbc.Driver");

        //2、建立连接
        Connection connection = DriverManager.
                getConnection("jdbc:mysql://master:3306/student",
                        "root",
                        "123456");

        //3、创建执行器
        Statement statement = connection.createStatement();

//        String sql ="insert into student(name,age,sex) values('test',25,'0')";

        String sql ="insert into student(name,age,sex) values(\""+name+"\","+age+",\""+sex+"\")";
        System.out.println(sql);
        int i = statement.executeUpdate(sql);
        System.out.println(i);
        if (i==1){
            System.out.println("注册成功");
        }else {
            System.out.println("注册失败");
        }

        statement.close();
        connection.close();


    }
}
